﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ForumServer;
using ForumServer.Forum;
using ForumLibrary;
using ForumLibrary.Data;

namespace ForumGUI
{
    public partial class NotificationFrame : Form
    {
        private ForumManager       _manager;
        private ClientController    _controller;
        private Notification        _notification;
        private String[]            _args;
        private bool                _Checkinout;

        public NotificationFrame(ref ForumManager manager, ClientController controller, Notification notification, String[] args)
        {
            InitializeComponent();
            startFrameInBottomRight();
            _controller = controller;
            _manager = manager;
            _notification = notification;
            _args = args; // args[0] = username, args[1] = forumname, args[2] =  threadname
            richTextBox1.Text = _controller.Username + " Alert: \n" + notification.NotificationMessage;
            timer1.Interval = 200;
            timer1.Enabled = true;
            timer1.Tick += new System.EventHandler(timer1_Tick);
        }
        /*
        private void NotificationLabel_Click(object sender, EventArgs e)
        {
            //this._controller.peekForm().Visible = false;
            switch (_notification.Type)
            { 
                case Iteration1Impl.Message.FriendAdded:
                    break;
                case Iteration1Impl.Message.FriendRemoved:
                    break;
                case Iteration1Impl.Message.ThreadAdded:
                    new ThreadsFrame(_controller, ref _manager, _args[1]).Visible = true;
                    this.Dispose(false);
                    break;
                case Iteration1Impl.Message.ThreadEdited:
                    new ThreadsFrame(_controller, ref _manager, _args[1]).Visible = true;
                    this.Dispose(false);
                    break;
                case Iteration1Impl.Message.ThreadDeleted:
                    new ThreadsFrame(_controller, ref _manager, _args[1]).Visible = true;
                    this.Dispose(false);
                    break;
                case Iteration1Impl.Message.PostAdded:
                    new PostsFrame(_controller, ref _manager, _args[1],_args[2]).Visible = true;
                    this.Dispose(false);
                    break;
                case Iteration1Impl.Message.PostEdited:
                    new PostsFrame(_controller, ref _manager, _args[1],_args[2]).Visible = true;
                    this.Dispose(false);
                    break;
                case Iteration1Impl.Message.PostDeleted:
                    new PostsFrame(_controller, ref _manager, _args[1],_args[2]).Visible = true;
                    this.Dispose(false);
                    break;
                default:
                    break;
            }

        }*/

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!DesignMode)
            {
                _Checkinout = true;
                Opacity = 1.0;
                timer1.Enabled = true;
            }
        }

       protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            if (this.Opacity > 0.2)
            {
                timer1.Enabled = true;
                e.Cancel = true;
            } 
        }
        
        private void timer1_Tick(object sender, EventArgs e)
        {


            if (this.Opacity > 0.1)
            {
                this.Opacity -= 0.012;
            }
            else
            {
                this.Close();
            } 
        }

        private void startFrameInBottomRight()
        {
            Rectangle r = Screen.PrimaryScreen.WorkingArea;
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width,
                Screen.PrimaryScreen.WorkingArea.Height - this.Height);
        }

   
    }
}
